import { axios } from '@/utils/request'

const api = {
  Login: '/auth',
  Logout: '/auth',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSmsErr: '/account_management/sms_err',
  // get my info
  UserInfo: '/user/info',

  PicCaptcha: '/pic-captcha',
  SmsCaptcha: '/sms-captcha',
  VerificationSmsCaptcha: '/verification-sms-captcha',
  ResetPassword: '/reset-password'
}

export function login (data) {
  return axios({
    url: '/auth',
    method: 'post',
    data
  })
}

export function refreshToken () {
  return axios({
    url: '/auth',
    method: 'put'
  })
}

export function getPicCaptcha (params) {
  return axios({
    url: api.PicCaptcha,
    method: 'get',
    params
  })
}

export function getSmsCaptcha (data) {
  return axios({
    url: api.SmsCaptcha,
    method: 'post',
    data
  })
}

export function verificationSmsCaptcha (data) {
  return axios({
    url: api.VerificationSmsCaptcha,
    method: 'post',
    data
  })
}

export function resetPassword (data) {
  return axios({
    url: `${api.ResetPassword}/${data.phone}`,
    method: 'patch',
    data
  })
}

export function getInfo () {
  return axios({
    url: '/auth/info',
    method: 'get'
  })
}

export function getCurrentUserNav (token) {
  return axios({
    url: '/user/nav',
    method: 'get'
  })
}

export function logout () {
  return axios({
    url: '/auth',
    method: 'delete'
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    data: parameter
  })
}
